package org.example.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.Dao.RPDao;
import org.example.Dao.URDao;
import org.example.Pojo.RP;
import org.example.Pojo.UR;
import org.example.Service.PermissionRelativeService;
import org.example.Service.PermissionSingleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
@Service
public class PermissionRelativeServiceImpl implements PermissionRelativeService {
    @Resource
    RPDao rpDao;
    @Resource
    URDao urDao;
    @Override
    public boolean DeleteRPByRoleId(String roleId) {
        QueryWrapper<RP> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        if (rpDao.delete(queryWrapper) > 0) {
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean DeleteRPByPermissionId(String permissionId) {
        QueryWrapper<RP> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("permission_id", permissionId);
        if (rpDao.delete(queryWrapper) > 0) {
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean DeleteURByRoleId(String roleId) {
        QueryWrapper<UR> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        if (urDao.delete(queryWrapper) > 0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean DeleteURByUserId(String userId) {
        QueryWrapper<UR> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        if (urDao.delete(queryWrapper) > 0) {
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean DeleteURByBoth(String userId, String roleId) {
        QueryWrapper<UR> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("role_id", roleId);
        if (urDao.delete(queryWrapper) > 0) {
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean DeleteRPByBoth(String permissionId, String roleId) {
        QueryWrapper<RP> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("permission_id", permissionId);
        queryWrapper.eq("role_id", roleId);
        if (rpDao.delete(queryWrapper) > 0) {
            return true;
        }else{
            return false;
        }
    }
}
